package pri.zey.custom.tools;/**
 * Created by Administrator on 2016/3/11.
 */

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>类描述
 * IO转换工具
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>属性描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>方法描述
 * getBitmapFromURL(String UrlStr)---->把图片地址转换Bitmap
 */
public class TIO {

    /**
     * 把图片地址转换Bitmap
     * @param UrlStr
     * @return
     */
    public static Bitmap getBitmapFromURL(String UrlStr){
        Bitmap mBitmap;
        InputStream is = null;
        try {
            URL url = new URL(UrlStr);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            is = new BufferedInputStream(connection.getInputStream());
            mBitmap = BitmapFactory.decodeStream(is);
            return mBitmap;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
